using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL
{
    public class ProgramROM : Component 
    {
        ProgramTable oProgram;
        public NodeVector O_IR;
        public NodeVector O_CONST;
        public NodeVector I_PC;

        public ProgramROM(Component poParentComponent, string psName, ProgramTable poProgram)
            : base(poParentComponent, psName)
        {
            oProgram = poProgram;
            O_IR = this.CreateNodeVector("IR_O", oProgram.IRWidth);
            O_CONST = this.CreateNodeVector("CONST_O", oProgram.ConstWidth);
            I_PC = this.CreateNodeVector("PC_I", oProgram.PCWidth);
        }

        public override void GenerateStructure()
        {
            ROM oProgROM = new ROM(this, "program_rom", oProgram.IRWidth + oProgram.ConstAddrWidth, oProgram.ProgramROM.Count);
            oProgROM.AddTable(oProgram.ProgramROM);

            ROM oConstROM = new ROM(this, "const_rom", oProgram.ConstWidth, oProgram.ConstantROM.Count);
            oConstROM.AddTable(oProgram.ConstantROM);

            oConstROM.I_Address.Join(oProgROM.O_Value.Subset(this, oProgram.IRWidth, oProgROM.O_Value.Width - 1));
            O_IR.Join(oProgROM.O_Value.Subset(this, 0, oProgram.IRWidth - 1));
            O_CONST.Join(oConstROM.O_Value);
            I_PC.Join(oProgROM.I_Address);
        }

    }
}
